/**
 * 接收客户端发送过来的信息，并进行业务处理
 */
package cn.com.klun.netty.server;

import cn.com.klun.business.TaskListenerServerService;
import cn.com.klun.netty.NettyMessage;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author chenmin-ds
 * 接收客户端发送过来的信息，并进行业务处理
 */
public class NettyServerTaskInfoHandler extends SimpleChannelInboundHandler<NettyMessage> {

	private Logger logger = LoggerFactory.getLogger("NettyServerTaskInfoHandler");
	
	private TaskListenerServerService taskListenerServerService;
	
	public NettyServerTaskInfoHandler(TaskListenerServerService taskListenerServerService){
		this.taskListenerServerService = taskListenerServerService;
	}
	
	@Override
	protected void channelRead0(ChannelHandlerContext ctx, NettyMessage msg)
			throws Exception {
		//接收服务传回来的信息
		Channel channel = ctx.channel();
		String ip = channel.remoteAddress().toString().replace("/", "");
		msg.setRequestKey(ip);
		logger.info("接收到客户端请求信息，并转发给业务处理接口,ip[{}],businessType[{}]." , ip , msg.getBusinessType());
		taskListenerServerService.businessAdapter(msg);
		
	}

}
